package com.wise.wing.views;

import java.util.ArrayList;
import java.util.List;




import com.wise.wing.R;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class RaitingBarForShowing extends LinearLayout {

	private Context mContext;
	private double rate = 0;
	private List<ImageView> views = new ArrayList<ImageView>();

	public RaitingBarForShowing(Context context) {
		this(context, null, 0);
	}

	public RaitingBarForShowing(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public RaitingBarForShowing(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		init();
	}

	private void init() {
		setOrientation(HORIZONTAL);
		setView();
	}

	private void setView() {
		removeAllViews();

		for (int i = 0; i < 10; i++) {
			ImageView imageView = new ImageView(mContext);
			if (i % 2 == 0) {
				imageView.setImageResource(R.drawable.star_gray_small_left);
			} else {
				imageView.setImageResource(R.drawable.star_gray_small_right);
			}
			views.add(imageView);
			addView(imageView);
		}
	}

	private void setViewStyle() {
		int current = (int) (rate);

		for (int i = 0; i < views.size(); i++) {
			ImageView imageView = views.get(i);
			if (i % 2 == 0) {
				if (i < current)
					imageView.setImageResource(R.drawable.star_yellow_small_left);
				else
					imageView.setImageResource(R.drawable.star_gray_small_left);
			} else {
				if (i < current)
					imageView.setImageResource(R.drawable.star_yellow_small_right);
				else
					imageView.setImageResource(R.drawable.star_gray_small_right);
			}
		}
	}

	public void setRate(double rate) {
		if (this.rate == rate)
			return;
		this.rate = rate;
		setViewStyle();
	}

}
